
<!DOCTYPE html>
<html>
    <head>
        <link href="style3.css" rel="stylesheet" type="text/css" />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        // connecting to the database
        $conn = mysql_connect('localhost', 'root', '') or die(mysql_error());
        mysql_select_db("mydb", $conn) or die(mysql_error());


// getting the id from the previous page (Nathalie)
        $paper_id = $_GET['paper_id'];


// Selecting version_id and path and ordering them descendingly to get the latest one
        $Latest_Version = mysql_query("SELECT version_id, path
                FROM version WHERE paper_id = '$paper_id' ORDER BY version_id DESC");


// Calls the path
        $row = mysql_fetch_assoc($Latest_Version);
        $data = $row['path'];


// Opens and reads the file
        $handle = fopen($data, 'r');
        $contents = fread($handle, filesize($data));
        fclose($handle);


// Adds PDF headers
        header("Content-type: application/pdf");


//Display PDF
        echo $contents;
// Closing connection
        mysql_close($conn);
        ?>
    </body>
</html>
